﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Services;
using System.ServiceModel;
using Contracts;
using System.ServiceModel.Description;

namespace Hosting
{
    class Program
    {
        static void Main(string[] args)
        {
            using (ServiceHost sh = new ServiceHost(typeof(CalculatorService)))
            {
                sh.AddServiceEndpoint(typeof(ICalculator), new WSHttpBinding(), "http://127.0.0.1:9999/calculatorservice");
                if (sh.Description.Behaviors.Find<ServiceMetadataBehavior>() == null)
                {
                    ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
                    behavior.HttpGetEnabled = true;
                    behavior.HttpGetUrl = new Uri("http://127.0.0.1:9999/calculatorservice");
                    sh.Description.Behaviors.Add(behavior);
                }
                sh.Opened += new EventHandler(sh_Opened);
                sh.Open();
                Console.Read();
            }
            

        }

        static void sh_Opened(object sender, EventArgs e)
        {
            Console.WriteLine("Calc服务已经启动，");
        }
    }
}
